# prompt
PS1='%B%F{blue}%~%F{magenta}${vcs_info_msg_0_}%F{cyan} >%f%b '
autoload -U vcs_info
precmd_functions+=(vcs_info)
zstyle ":vcs_info:*" enable git
zstyle ":vcs_info:*" formats " (%b)"
setopt PROMPT_SUBST

# history
HISTFILE="$HOME/.local/share/zsh/history"
HISTSIZE=4096
SAVEHIST=4096
setopt HIST_IGNORE_ALL_DUPS HIST_IGNORE_SPACE HIST_REDUCE_BLANKS SHARE_HISTORY

# completion
autoload -U compinit
zmodload zsh/complist
_comp_options+=(globdots)
zstyle ":completion:*" menu select
zstyle ":completion:*" matcher-list 'm:{[:lower:]}={[:upper:]}'

# navigation
setopt AUTO_CD

# redirection
setopt APPEND_CREATE NO_CLOBBER

# keymaps
bindkey -e
bindkey "^[[3~" delete-char
bindkey -M menuselect "^n" menu-complete
bindkey -M menuselect "^p" reverse-menu-complete
bindkey "^[[B" history-substring-search-down "^n" history-substring-search-down
bindkey "^[[A" history-substring-search-up "^p" history-substring-search-up
bindkey -s "^o" "lfcd\n"
setopt NO_FLOW_CONTROL

# aliases
alias \
    vim="nvim" \
    ..="cd .." \
    ...="cd ../.." \
    ....="cd ../../.." \
    -- -="cd -" \
    ls="ls -Fv" \
    la="ls -AFhv" \
    ll="ls -lAFhv" \
    cp="cp -riv" \
    mv="mv -iv" \
    rm="rm -I" \
    mkdir="mkdir -pv" \
    df="df -h" \
    du="du -ch" \
    grep="grep -i"

# functions
lfcd() { cd "$(command lf -print-last-dir "$@")"; }

weather() { clear && curl -s "wttr.in/${*// /+}?FT"; }

cheat() { curl -s "cheat.sh/${*// /+}?T" | less; }

extract() {
    case "$1" in
        *.tar.bz2 | *.tbz2) tar -xjf "$1" ;;
        *.tar.gz | *.tgz) tar -xzf "$1" ;;
        *.tar.xz | *.txz) tar -xJf "$1" ;;
        *.zip) unzip -nq "$1" -d "${1%.zip}" ;;
    esac
}

# plugins
source "$HOME/.local/share/zsh/zsh-autosuggestions/zsh-autosuggestions.zsh" 2> /dev/null
source "$HOME/.local/share/zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" 2> /dev/null
source "$HOME/.local/share/zsh/zsh-history-substring-search/zsh-history-substring-search.zsh" 2> /dev/null
